package vi.org.rongcloud19test.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import java.util.ArrayList;

import vi.org.rongcloud19test.R;
import vi.org.rongcloud19test.database.UserInfos;

/**
 * Created by Vicky on 2015/11/18.
 * RongCloudChatTest
 * contact way: 317461087@qq.com
 */
public class FriendListAdapter extends BaseAdapter {

    private Context mContext;
    private ArrayList<UserInfos> mFriendsList;
    private LayoutInflater inflater;
    private ViewHolder viewHolder;

    class ViewHolder{
        TextView name;
    }
    public FriendListAdapter(Context context, ArrayList<UserInfos> friends)
    {
        this.mContext = context;
        this.mFriendsList = friends;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mFriendsList.size();
    }

    @Override
    public Object getItem(int i) {
        return mFriendsList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        View v = view;
        if(null == v)
        {
            v = inflater.inflate(R.layout.activity_friendlist_item,null);
            viewHolder = new ViewHolder();
            viewHolder.name = (TextView)v.findViewById(R.id.friend_name);
            v.setTag(viewHolder);
        }
        else {
            viewHolder = (ViewHolder)v.getTag();
        }
        viewHolder.name.setText( mFriendsList.get(i).getUsername());

        return v;
    }
}
